package com.atguigu.gmall.file;

import org.springframework.scheduling.annotation.Async;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 异步 编排
 */
public class CompletableFutureDemo1 {

    public static ThreadPoolExecutor threadPoolExecutor =
            new ThreadPoolExecutor(2,
                    5,
                    10,
                    TimeUnit.SECONDS,
                    new ArrayBlockingQueue(100)

            );
    //创建一个多线程
    public static void main(String[] args) throws Exception {

        CompletableFuture<String> result = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            int i = 1/0;
            return "one";
        }, threadPoolExecutor).whenCompleteAsync((t,u) -> {
            System.out.println("t:" + t);
            System.out.println("u:" + u);
        },threadPoolExecutor).exceptionally((t) -> {
            System.out.println(t);
            return "打日志有异常了";
        });
        System.out.println(result.get());
    }
}
